/*
 * @Author: szx
 * @Date: 2022-03-16 15:12:00
 * @LastEditTime: 2022-03-16 15:17:07
 * @Description:
 * @FilePath: \leetcode\剑指offer\07\07.js
 */
/**
 * Definition for a binary tree node.
 * function TreeNode(val) {
 *     this.val = val;
 *     this.left = this.right = null;
 * }
 */
/**
 * @param {number[]} preorder
 * @param {number[]} inorder
 * @return {TreeNode}
 */
var buildTree = function (preorder, inorder) {
    if (!preorder.length) return null;
    const rootVal = preorder.shift();
    const root = new TreeNode(rootVal);
    const index = inorder.indexOf(rootVal);
    root.left = buildTree(preorder.slice(0, index), inorder.slice(0, index));
    root.right = buildTree(preorder.slice(index), inorder.slice(index + 1));
    return root;
};
